package cn.com.oceansoft.business.os.service.impl;

import cn.com.oceansoft.business.base.entity.Pager;
import cn.com.oceansoft.business.base.entity.Query;
import cn.com.oceansoft.business.base.entity.Result;
import cn.com.oceansoft.business.os.entity.Choose;
import cn.com.oceansoft.business.os.entity.Lucky;
import cn.com.oceansoft.business.os.persistence.IChooseMapper;
import cn.com.oceansoft.business.os.service.IChooseService;
import cn.com.oceansoft.nos.common.util.web.PageUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created by zhangxl on 2016/12/30.
 */

@Service
public class ChooseServiceImpl implements IChooseService {

    @Resource
    private IChooseMapper chooseMapper;

    @Override
    public Pager<Choose> findPageByCondition(Query query) {
        PageHelper.startPage(query.getPageNum(), query.getNumPerPage(), true);
        return PageUtil.page2pager((Page<Choose>) chooseMapper.findPageByCondition(query), query);
    }

    @Override
    @Transactional
    public void delete(String id) {
        chooseMapper.delete(id);
    }

    @Override
    public Result save(Choose choose) {
        int id = chooseMapper.save(choose);
        if (0 < id) {
            choose.setId(id);
            return new Result(Result.SUCC, choose);
        } else {
            return new Result(Result.FAILURE, "新增失败！");
        }
    }

    @Override
    public Choose findChooseById(int id) {
        return chooseMapper.findChooseById(id);
    }

    @Override
    public Result update(Choose choose) {
        int id = chooseMapper.update(choose);
        if (1 == id) {
            return new Result(Result.SUCC, choose);
        } else {
            return new Result(Result.FAILURE, "更新失败！");
        }
    }
}
